package com.yixun.qfbao.hander;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.yixun.qfbao.api.service.ChannelRoleService;
import com.yixun.qfbao.apidto.GetRoleByIdReqDto;
import com.yixun.qfbao.apidto.GetRoleByIdResDto;
import com.yixun.qfbao.dto.base.BaseRequestDTO;
import com.yixun.qfbao.dto.base.BaseResponseDTO;
import com.yixun.qfbao.hander.base.CommonAbstractHander;
import com.yixun.qfbao.vo.GetRoleByIdReqVo;
import com.yixun.qfbao.xf.model.enums.ResultEnum;

/**
 * @author guifang.weng
 * @create 2017-11-22 14:42
 **/
@Service
public class GetRoleByIdHander extends CommonAbstractHander {
    private static Logger logger= LoggerFactory.getLogger(GetRoleByIdHander.class);

    @Autowired
    private ChannelRoleService channelRoleService;

    @Override
    public BaseResponseDTO doBusiness(BaseRequestDTO reqDto) {
        BaseResponseDTO<GetRoleByIdResDto> res = new BaseResponseDTO<>();
        GetRoleByIdResDto resDto = new GetRoleByIdResDto();
        GetRoleByIdReqVo reqVo = (GetRoleByIdReqVo)reqDto;
        GetRoleByIdReqDto getRoleByIdReqDto = reqVo.getParams();
        try {
            resDto = channelRoleService.getRoleById(getRoleByIdReqDto);
        } catch (Exception e) {
            logger.error("GetRoleByIdHander error: {}", e);
            res.setResult(ResultEnum.FAIL.getNo());
            res.setErrorMsg("获取角色信息失败");
        }
        res.setResult(resDto.getResult());
        res.setResData(resDto);
        return res;
    }
}
